package Tydzien11Test;

import static org.junit.Assert.*;

import java.awt.Color;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;

import org.junit.Test;

import Tydzien10.OrganizerEvent;
import Tydzien11.OrganizerEventsDatabase;

public class OrganizerEventsDatabaseTest {

	@Test
	public void loadTest() throws SQLException {
		ArrayList<OrganizerEvent> events = OrganizerEventsDatabase.loadFromDatabase();
		ArrayList<OrganizerEvent> expected = new ArrayList<OrganizerEvent>();
		Calendar startDate = Calendar.getInstance();
		Calendar endDate = Calendar.getInstance();
		
		startDate.set(2015, 2, 18, 21, 37); startDate.set(Calendar.SECOND, 0); startDate.set(Calendar.MILLISECOND, 0);
		endDate.set(2015, 2, 18, 22, 37); endDate.set(Calendar.SECOND, 0); endDate.set(Calendar.MILLISECOND, 0);
		expected.add(new OrganizerEvent(startDate, endDate, "Spotkanie na szczycie 1", new Color(1.0f, 0.0f, 0.0f)));
		
		startDate.set(2015, 3, 19, 21, 37); startDate.set(Calendar.SECOND, 0); startDate.set(Calendar.MILLISECOND, 0);
		endDate.set(2015, 3, 20, 21, 38); endDate.set(Calendar.SECOND, 0); endDate.set(Calendar.MILLISECOND, 0);
		expected.add(new OrganizerEvent(startDate, endDate, "Spotkanie na szczycie 2", new Color(0.0f, 1.0f, 0.0f)));
		
		startDate.set(2015, 4, 20, 21, 37); startDate.set(Calendar.SECOND, 0); startDate.set(Calendar.MILLISECOND, 0);
		endDate.set(2015, 4, 20, 21, 38); endDate.set(Calendar.SECOND, 0); endDate.set(Calendar.MILLISECOND, 0);
		expected.add(new OrganizerEvent(startDate, endDate, "Spotkanie na szczycie 3", new Color(0.0f, 0.0f, 1.0f)));
		
		for(int i = 0; i < 3; ++i)
		{
			assertEquals(expected.get(i).toString(), events.get(i).toString());
		}
	}
	
	@Test
	public void saveTest() throws SQLException {
		ArrayList<OrganizerEvent> events = new ArrayList<OrganizerEvent>();
		Calendar startDate = Calendar.getInstance();
		Calendar endDate = Calendar.getInstance();
		
		startDate.set(2015, 2, 18, 21, 37); startDate.set(Calendar.SECOND, 0); startDate.set(Calendar.MILLISECOND, 0);
		endDate.set(2015, 2, 18, 22, 37); endDate.set(Calendar.SECOND, 0); endDate.set(Calendar.MILLISECOND, 0);
		events.add(new OrganizerEvent(startDate, endDate, "Spotkanie na szczycie 1", new Color(1.0f, 0.0f, 0.0f)));
		
		startDate.set(2015, 3, 19, 21, 37); startDate.set(Calendar.SECOND, 0); startDate.set(Calendar.MILLISECOND, 0);
		endDate.set(2015, 3, 20, 21, 38); endDate.set(Calendar.SECOND, 0); endDate.set(Calendar.MILLISECOND, 0);
		events.add(new OrganizerEvent(startDate, endDate, "Spotkanie na szczycie 2", new Color(0.0f, 1.0f, 0.0f)));
		
		startDate.set(2015, 4, 20, 21, 37); startDate.set(Calendar.SECOND, 0); startDate.set(Calendar.MILLISECOND, 0);
		endDate.set(2015, 4, 20, 21, 38); endDate.set(Calendar.SECOND, 0); endDate.set(Calendar.MILLISECOND, 0);
		events.add(new OrganizerEvent(startDate, endDate, "Spotkanie na szczycie 3", new Color(0.0f, 0.0f, 1.0f)));
		
		OrganizerEventsDatabase.saveToDatabase(events);
	}

}
